using System;
using System.Collections.Generic;
using System.Text;
using System.Net.Sockets;
using System.Net;
using System.Threading;

namespace Servidor
{
    class Program
    {
        static NetworkStream canalA;
        static NetworkStream canalB;
        static void Main(string[] args)
        {
            TcpListener servidor = new TcpListener(IPAddress.Any, 9090);
            servidor.Start();

            TcpClient clienteA = servidor.AcceptTcpClient();
            TcpClient clienteB = servidor.AcceptTcpClient();

            canalA = clienteA.GetStream();//
            canalB = clienteB.GetStream();//

            Thread a_b = new Thread(A_B);
            Thread b_a = new Thread(B_A);
            a_b.Start();
            b_a.Start();

            
        }

        static void A_B() 
        {
            while (true) {
                byte[] datos = new byte[1000];
                canalA.Read(datos, 0, datos.Length);
                canalB.Write(datos, 0, datos.Length);    
            }
        }

        static void B_A()
        {
            while (true)
            {
                byte[] datos = new byte[1000];
                canalB.Read(datos, 0, datos.Length);
                canalA.Write(datos, 0, datos.Length);
            }
        }
    }
}
